#include "trader.h"

trader::trader(QWidget *parent) : QWidget(parent)
{

}

trader::trader(int cost1, int cost2, int cost3)
{
    _cost1=cost1;
    _cost2=cost2;
    _cost3=cost3;

    setFixedSize(500,400);
    setWindowIcon(QPixmap("://images/72.png"));
    setWindowTitle("商人");
    storeList=new QListWidget;
    label=new QLabel(this);

    if(cost1>0){
        label->setText("卖钥匙，点击需要的选项");
        storeList->addItem("买一把红钥匙:消耗"+QString::number(cost1,10)+"金币");
        storeList->addItem("买一把蓝钥匙:消耗"+QString::number(cost2,10)+"金币");
        storeList->addItem("买一把黄钥匙:消耗"+QString::number(cost3,10)+"金币");
    }
    else{
        label->setText("买钥匙，点击需要的选项");
        storeList->addItem("卖一把红钥匙:获得"+QString::number(-cost1,10)+"金币");
        storeList->addItem("卖一把蓝钥匙:获得"+QString::number(-cost2,10)+"金币");
        storeList->addItem("卖一把黄钥匙:获得"+QString::number(-cost3,10)+"金币");
    }

    storeList->addItem("退出商店");

    ConPB=new QPushButton("确定");
    ConPB->setShortcut(Qt::Key_Enter);

    QVBoxLayout *pMain=new QVBoxLayout;
    pMain->addWidget(label);
    pMain->addWidget(storeList);
    pMain->addWidget(ConPB);

    setLayout(pMain);

    connect(ConPB,SIGNAL(clicked(bool)),this,SLOT(selectId()));
}

void trader::selectId()
{
    emit(sendId(storeList->currentRow()));
}
